package array;

import java.util.Scanner;

public class ArrayDemo03 {
    public static void main(String[] args) {
//        动态初始化数组
        //数据类型[] 数组名 = new 数据类型[]
        int[] ages = new int[3];
        System.out.println(ages[0]);  //int类型默认值为0
        System.out.println(ages[1]);  //int类型默认值为0
        System.out.println(ages[2]);  //int类型默认值为0

        ages[0] = 18;
        ages[1] = 19;
        ages[2] = 21;
        System.out.println(ages[0]);
        System.out.println(ages[1]);
        System.out.println(ages[2]);

//        评委打分，求总分和平均分
        Scanner sc = new Scanner(System.in);
        //建立一个数组
        double[] scores = new double[6];
        //对数组进行遍历
        for (int i = 0; i < scores.length; i++) {
            System.out.println("请您输入第" + (i + 1) + "个评委的打分为：");
            double score = sc.nextInt();
            scores[i] = score;  //将输入的值赋值给元素
        }
        //定义一个变量
        double sum = 0;
        for (int i = 0; i < scores.length; i++) {
            sum += scores[i]; // 将元素相加
        }
        System.out.println(sum);
        System.out.println(sum / scores.length);
    }
}
